package com.group7d.util;

import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * Created by Jinshulin on 2016/6/23.
 */
public class SystemConfig {

    public static String dbUrl;
    public static String dbUserName;
    public static String dbPassword;

    public static boolean initSystemConfig(String systemConfigFile) {

        try {

            Properties prop = new Properties();
            prop.load(new InputStreamReader(new FileInputStream(systemConfigFile), "UTF8"));
//            prop.load(SystemConfig.class.getClassLoader().getResourceAsStream("application.properties"));
            dbUrl = prop.getProperty("db.url");
            dbUserName = prop.getProperty("db.username");
            dbPassword = prop.getProperty("db.password");

            return true;
        } catch (Exception e) {
            e.getStackTrace();
            return false;
        }
    }

    public static Connection getConnection() throws SQLException {
        return DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
    }
}
